#!/usr/bin/env python

import sys
sys.path.append('../')
from model_helper import ModelRunner

def execute_model():
    print('---> 1')
    if len(sys.argv)>1:
        modelex = ModelRunner(sys.argv[1])
    else: 
        modelex = ModelRunner(False)
    print('---> 2')
    modelex.print_headline("Run MODEL to produce NPV cube and exposures")
    modelex.run("Input/model.xml")
    modelex.get_times("Output/log.txt")
    print('---> 3')
    modelex.print_headline("Run MODEL again to price European Swaptions")
    modelex.run("Input/model_swaption.xml")

    modelex.print_headline("Plot results: Simulated exposures vs analytical swaption prices")

    modelex.setup_plot("swaptions")
    modelex.plot("exposure_trade_Swap_20y.csv", 2, 3, 'b', "Swap EPE")
    modelex.plot("exposure_trade_Swap_20y.csv", 2, 4, 'r', "Swap ENE")
    modelex.plot_npv("swaption_npv.csv", 6, 'g', "NPV Swaptions", marker='s')
    modelex.decorate_plot(title="Example 1 - Simulated exposures vs analytical swaption prices")
    modelex.save_plot_to_file()

if __name__ == '__main__':
    execute_model()